<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('项目信息列表')" />
    <style>
        .select-list li p, .select-list li label:not(.radio-box) {
            float: left;
            width: 100px;
            margin: 5px 0px 0px 0px;
            text-align: right;
        }
    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <input type="hidden" th:value="${@ShiroUtils.getUserId()}" id="loginUserId"/>
                <div class="select-list">
                    <ul>
                        <li>
                            <label>项目名称：</label>
                            <input type="text" name="projectName"/>
                        </li>
                        <li>
                            <label>立项时间：</label>
                            <input type="text" class="time-input" placeholder="请选择立项时间" name="approvalTime"/>
                        </li>
                        <li>
                            <label>计划开始时间：</label>
                            <input type="text" class="time-input" placeholder="请选择计划开始时间" name="plannedStartTime"/>
                        </li>
                        <li>
                            <label>计划结束时间：</label>
                            <input type="text" class="time-input" placeholder="请选择计划结束时间" name="plannedEndTime"/>
                        </li>
                        <li>
                            <label>项目负责人：</label>
                            <select name="ownerId" class="user-select form-control" ></select>
                        </li>
                        <li>
                            <label>项目状态：</label>
                            <select class="form-control" name="status" th:with="type=${@dict.getType('project_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>部门：</label>
                            <input type="text" name="department"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="projects:projects:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="projects:projects:export">
                <i class="fa fa-download"></i> 导出
            </a>
            <a class="btn btn-primary" onclick="openProjectView()" shiro:hasPermission="projects:projects:view">
                <i class="fa fa-search"></i> 项目视图
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: select2-css" />
<th:block th:include="include :: select2-js" />
<script th:inline="javascript">
    var detailFlag = [[${@permission.hasPermi('projects:projects:detail')}]];
    var removeFlag = [[${@permission.hasPermi('projects:projects:remove')}]];
    var editFlag = [[${@permission.hasPermi('projects:projects:edit')}]];
    var addProgressFlag = [[${@permission.hasPermi('projects:progress:add')}]];
    var statusDatas = [[${@dict.getType('project_status')}]];
    var prefix = ctx + "projects/projects";
    var prefix1 = ctx + "projects/progress";

    function openProjectView() {
        $.modal.openTab("项目视图", prefix + "/view");
    }

    $("#add-btn").click(function(){
        $.modal.open("添加项目", prefix + "/add");
    })

    $(function() {
        $(".user-select").select2({
            placeholder: '--选择用户--',
            allowClear: true,
            ajax: {
                url: '/system/user/selectList',
                delay: 250,
                cache: true,
                data: function (params) {
                    return {
                        userName: params.term
                    };
                }
            }
        });
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            detailUrl: prefix + "/detail/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "项目信息",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '项目编号',
                    visible: true
                },
                {
                    field: 'projectName',
                    title: '项目名称',
                    formatter: function(value, row, index) {
                        return value
                    }
                },
                {
                    field: 'department',
                    title: '部门'
                },
                {
                    field: 'approvalTime',
                    title: '立项时间'
                },
                {
                    field: 'plannedTime',
                    title: '计划时间',
                    formatter: function(value, row, index) {
                        let startTime = row.plannedStartTime == null ? "" : row.plannedStartTime;
                        let endTime = row.plannedEndTime == null ? "" : row.plannedEndTime;
                        return startTime + " - " + endTime;
                    }
                },
                {
                    field: 'owner.userName',
                    title: '项目负责人'
                },
                {
                    field: 'status',
                    title: '项目状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'lastProgress',
                    title: '项目进度',
                    formatter: function(value, row, index) {
                        if (value != null) {
                            return value.progressContent;
                        }
                        return "";
                    }
                },
                {
                    field: 'lastProgress',
                    title: '技术协议进度',
                    formatter: function(value, row, index) {
                        if (value != null) {
                            return value.technicalAgreementProgress;
                        }
                        return "";
                    }
                },
                {
                    title: '操作',
                    align: 'left',
                    width: "140px",
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-warning btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\')"><i class="fa fa-search"></i>详细</a> ');
                        var more = [];
                        more.push("<a class='btn btn-success btn-xs " + editFlag + "' href='javascript:void(0)' onclick='$.operate.edit(" + row.id + ")'><i class='fa fa-edit'></i>编辑</a> ");
                        more.push("<a class='btn btn-info btn-xs " + addProgressFlag + "' href='javascript:void(0)' onclick='addProgress(" + row.id + ")'><i class='fa fa-plus'></i>项目进度</a> ");
                        more.push("<a class='btn btn-danger btn-xs " + removeFlag + "' href='javascript:void(0)' onclick='$.operate.remove(" + row.id + ")'><i class='fa fa-remove'></i>删除</a> ");
                        actions.push('<a tabindex="0" class="btn btn-info btn-xs" role="button" data-container="body" data-placement="left" data-toggle="popover" data-html="true" data-trigger="hover" data-content="' + more.join('') + '"><i class="fa fa-chevron-circle-right"></i>更多操作</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function addProgress(id) {
        $.modal.open("添加项目进度", prefix1 + "/add/" + id);
    }
</script>
</body>
</html>